package frame.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

//这个类当前只是用来实验SPRING mvc中的拦截器的用法
public class InterceptorTest implements HandlerInterceptor {

	@Autowired
	 private Cache  ehCache;

	public boolean preHandle(HttpServletRequest request,  
	        HttpServletResponse response, Object handler) throws Exception {  
//		HttpServletRequest hreq=(HttpServletRequest)request;
//		System.out.println("------------->>>>>>>>>>>>>>>>>>>>>"+hreq.getRequestURI());
		
//		Cache s=ehCache.getCacheManager().getCache("shiro.authorizationCache");
//		System.out.println(s);
//		Object ss=request.getSession().getAttribute("JSESSIONID");
//		System.out.println(ss);
//		System.out.println("in interceptor sessionID is "+SecurityUtils.getSubject().getSession().getId());
//	    System.out.println("------------------Pre-handle");  
//		 Element e=ehCache.get("admin0");
//		 if(e!=null){
//			 System.out.println("ehCache:"+e.getObjectValue());
//		 }
//		 System.out.println(request.getParameter("roles"));
//		 System.out.println(request.getParameter("uri"));
	    return true;  
	}  
	  
	@Override  
	public void postHandle(HttpServletRequest request,  
	        HttpServletResponse response, Object handler,  
	        ModelAndView modelAndView) throws Exception {  
	    System.out.println("------------------Post-handle");  
	}  
	  
	@Override  
	public void afterCompletion(HttpServletRequest request,  
	        HttpServletResponse response, Object handler, Exception ex)  
	        throws Exception {  
	    System.out.println("------------------After completion handle");  
	}
	

}
